package com.gaoch.simweather.ui.weather

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.gaoch.simweather.logic.Repository
import com.gaoch.simweather.logic.model.HourlyResponse
import com.gaoch.simweather.logic.model.Weather


class WeatherViewModel: ViewModel() {
    private val locationLiveData=MutableLiveData<String>()

    //location可以用城市名，城市id来替代
    var location=""

    //城市名
    var cityName=""

    var hourlyWeather=ArrayList<HourlyResponse.HourWeather>()

    val weatherLiveData=Transformations.switchMap(locationLiveData){
        Repository.getWeather(it)
    }

    fun refreshWeather(location:String){
        locationLiveData.value=location
    }
}